<?php

namespace common\components;

use yii;

class Formatter
{

    public function formatCurrency($currency)
    {
        if ($currency < 10000) {
            $title = $currency;
        } elseif ($currency > 10000 && $currency < 100000000) {
            $title = floor($currency / 10000);
            $mod = $currency % 10000;
            $title = $mod > 0 ? $title . '万' . $mod : $title . '万';
        } elseif ($currency > 100000000) {
            $title = $yi = floor($currency / 100000000);
            $floor_re = floor(($currency - $title * 100000000) / 10000);
            $title = $floor_re > 0 ? $title . '亿' . $floor_re . '万' : $title . '亿';
            $mod = ($currency - ($yi * 10000 + $floor_re) * 10000) % 10000;
            $title = $mod > 0 ? $title . $mod : $title;
        }
        return $title;
    }
}